package com.ax.base.drugstore.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ax.base.common.domain.Tree;
import com.ax.base.drugstore.domain.BaseDrugstore;
import com.ax.base.system.domain.MenuDO;

@Mapper
public interface BaseDrugstoreMapper {
    int deleteByPrimaryKey(Long drugstoreId);

    int insert(BaseDrugstore record);

    /**
	 * 药房保存(模块:药房管理)
	 * 
	 * @param BaseDrugstore baseDrugstore
	 *           
	 * @return SUCC
	 */
    @Insert("<script>"+
    	  "insert into base_drugstore (Drugstore_ID, Drugstore_Name, First_Letter,"+ 
	      "Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
	      "Reg_capital, Area_Code, Area_Name,"+ 
	      "Phone, Address, Open_Date,"+ 
	      "Longitude, Latitude, Account,"+ 
	      "BANK, Credit_Code, Introduction,"+ 
	      "Remarks, Parent_Drugstore_ID, Drugstore_Type,"+ 
	      "create_date, update_date, Flag"+
	       ")"+
	      "values (#{drugstoreId}, #{drugstoreName}, #{firstLetter},"+ 
	      "#{legalPersonName}, #{legalPersonId}, #{regDate},"+ 
	      "#{regCapital}, #{areaCode}, #{areaName},"+ 
	      "#{phone}, #{address}, #{openDate},"+ 
	      "#{longitude}, #{latitude}, #{account},"+ 
	      "#{bank}, #{creditCode}, #{introduction},"+ 
	      "#{remarks}, #{parentDrugstoreId}, #{drugstoreType},"+ 
	      "NOW(), NOW(), #{flag}"+
	      ")"+
    	  "</script>")
     int insertSelective(BaseDrugstore record);

    /**
	 * 药房增加(模块:药房管理)*跳转增加页面
	 * 
	 * @param Long pId
	 *           
	 * @return BaseDrugstore BaseDrugstore
	 */
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag "+
    "from base_drugstore "+
    "where Drugstore_ID = #{drugstoreId}" + 
    "</script>")
    BaseDrugstore selectByPrimaryKey(Long drugstoreId);

    /**
	 * 药房修改(模块:药房管理)
	 * 
	 * @param BaseDrugstore baseDrugstore
	 *           
	 * @return SUCC
	 */	
   @Update("<script>"+
    "update base_drugstore"+
		    "<set >"+
		    "<if test=\"drugstoreName != null and drugstoreName != ''\">"+ "Drugstore_Name = #{drugstoreName}, " + "</if>" + 
		    "<if test=\"firstLetter != null and firstLetter != ''\">"+ "First_Letter = #{firstLetter}, " + "</if>" + 
		    "<if test=\"legalPersonName != null and legalPersonName != ''\">"+ "Legal_Person_Name = #{legalPersonName}, " + "</if>" + 
		    "<if test=\"legalPersonId != null\">"+ "Legal_Person_ID = #{legalPersonId}, " + "</if>" + 
		    "<if test=\"regDate != null\">"+ "Reg_Date = #{regDate}, " + "</if>" + 
		    "<if test=\"regCapital != null and regCapital != ''\">"+ "Reg_capital = #{regCapital}, " + "</if>" + 
		    "<if test=\"areaCode != null\">"+ "Area_Code = #{areaCode}, " + "</if>" + 
		    "<if test=\"areaName != null and areaName != ''\">"+ "Area_Name = #{areaName}, " + "</if>" + 
		    "<if test=\"phone != null and phone != ''\">"+ "Phone = #{phone}, " + "</if>" + 
		    "<if test=\"address != null and address != ''\">"+ "Address = #{address}, " + "</if>" + 
		    "<if test=\"openDate != null\">"+ "Open_Date = #{openDate}, " + "</if>" + 
		    "<if test=\"longitude != null\">"+ "Longitude = #{longitude}, " + "</if>" + 
		    "<if test=\"account != null and account != ''\">"+ "Account = #{account}, " + "</if>" +
		    "<if test=\"latitude != null and latitude != ''\">"+ "Latitude = #{latitude}, " + "</if>" +
		    "<if test=\"bank != null and bank != ''\">"+ "BANK = #{bank}, " + "</if>" +
		    "<if test=\"creditCode != null\">"+ "Credit_Code = #{creditCode}, " + "</if>" +
		    "<if test=\"latitude != null and latitude != ''\">"+ "Latitude = #{latitude}, " + "</if>" +
		    "<if test=\"introduction != null\">"+ "Introduction = #{introduction}, " + "</if>" +
		    "<if test=\"remarks != null\">"+ "Remarks = #{remarks}, " + "</if>" +
		    "<if test=\"parentDrugstoreId != null\">"+ "Parent_Drugstore_ID = #{parentDrugstoreId}, " + "</if>" +
		    "<if test=\"drugstoreType != null\">"+ "Drugstore_Type = #{drugstoreType}, " + "</if>" +
		    "<if test=\"createDate != null\">"+ "create_date = #{createDate}, " + "</if>" +
		    "<if test=\"beginDate != null\">"+ "Begin_date = #{beginDate}, " + "</if>" +
		    "<if test=\"endDate != null\">"+ "End_date = #{endDate}, " + "</if>" +
		    "<if test=\"remindDays != null\">"+ "Remind_Days = #{remindDays}, " + "</if>" +
		    "<if test=\"cost != null\">"+ "Cost = #{cost}, " + "</if>" +
		    "<if test=\"remindCost != null\">"+ "Remind_Cost = #{remindCost}, " + "</if>" +
		    "<if test=\"drugstoreType != null\">"+ "Drugstore_Type = #{drugstoreType}, " + "</if>" +
		    "update_date = NOW()," + 
		    "<if test=\"flag != null\">"+ "Flag = #{flag}, " + "</if>" +
		    "</set>"+
		    "where Drugstore_ID = #{drugstoreId,jdbcType=BIGINT}"+
		    "</script>")
    int updateByPrimaryKeySelective(BaseDrugstore record);

    int updateByPrimaryKey(BaseDrugstore record);
    
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag,Recharge_Type,Begin_date,End_date,Remind_Days,Cost,Remind_Cost "+
    "from base_drugstore"+
    "<where>" + 
 	"<if test=\"drugstoreId != null\">"+ "and Drugstore_ID = #{drugstoreId} " + "</if>" + 
 	"</where>"+ 
    "</script>")
    List<BaseDrugstore> queryDrugStoreMapper(Map<String,Object> map);
    
    /**
	 * 药店名是否重复(新增)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag,Recharge_Type,Begin_date,End_date,Remind_Days,Cost,Remind_Cost "+
    "from base_drugstore where Drugstore_Name = #{drugstoreName} and Parent_Drugstore_ID = #{parentDrugstoreId}"+
    "</script>")
    List<BaseDrugstore> drugstoreNameValidateMapper(Map<String,Object> map);

    /**
	 * 代码是否重复(新增)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag,Recharge_Type,Begin_date,End_date,Remind_Days,Cost,Remind_Cost "+
    "from base_drugstore where Credit_Code = #{creditCode}"+
    "</script>")
    List<BaseDrugstore> creditCodeValidateMapper(Map<String,Object> map);
    
    
    /**
	 * 药店名是否重复(修改)
	 * 
	 * @param String parameter
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag,Recharge_Type,Begin_date,End_date,Remind_Days,Cost,Remind_Cost "+
    "from base_drugstore where Drugstore_Name = #{drugstoreName} and Parent_Drugstore_ID = #{parentDrugstoreId} and Drugstore_ID != #{drugstoreId}"+
    "</script>")
    List<BaseDrugstore> updateDrugstoreNameValidateMapper(Map<String,Object> map);
    
    /**
	 * 代码是否重复(修改)
	 * 
	 * @param Map<String,Object> map
	 *         
	 * @return boolean
	 */
    @Select("<script>" +
    		"select "+ 
    "Drugstore_ID menuId, Drugstore_Name name,First_Letter, Legal_Person_Name, Legal_Person_ID, Reg_Date,"+ 
    "Reg_capital, Area_Code, Area_Name, Phone, Address, Open_Date, Longitude, Latitude,"+ 
    "Account, BANK, Credit_Code, Introduction, Remarks, Parent_Drugstore_ID parentId, Drugstore_Type type,"+ 
    "create_date, update_date, Flag,Recharge_Type,Begin_date,End_date,Remind_Days,Cost,Remind_Cost "+
    "from base_drugstore where Credit_Code = #{creditCode} and Drugstore_ID != #{drugstoreId}"+
    "</script>")
    List<BaseDrugstore> updateCreditCodeValidateMapper(Map<String,Object> map);
    
    /** Tree
	 * 
	 * @param Long parentDrugstoreId
	 *           
	 * @return Tree<MenuDO>
	 */
    @Select("SELECT Drugstore_ID id,Drugstore_Name text, Parent_Drugstore_ID parentId FROM base_drugstore")
    List<Tree<MenuDO>> listDrugDepId();
    
}